import Router from 'koa-router'

const router = new Router({ prefix: '/admUsers' })
const { lognameExisted, admIdisExist, isTheBestRole, checkRoleisAdm } = require('../middleware/admUsers.middleware')
const { auth } = require('../middleware/auth.middleware')
const { getAdms, getAuthorizationCode, getlogname, getAdmById, addAdm, updateAdm, deleteAdmById } = require('../controller/admUsers.controller') 

/**
 * 管理员模块
 * @description admUsers
 */
router.get('/', getAdms) // 获取所有管理员(分页可选)
router.get('/getAuthorizationCode', getAuthorizationCode) // 获取授权码
router.get('/logname', lognameExisted, getlogname) // 根据名字模糊获取所有管理员(分页可选)
router.get('/:id', admIdisExist, getAdmById) // 根据id获取所有管理员(分页可选)
router.post('/', auth, isTheBestRole, addAdm) // 添加管理员
router.put('/adm/:id', auth, isTheBestRole, checkRoleisAdm, updateAdm) // 更新管理员信息
router.delete('/:id', auth, admIdisExist, isTheBestRole, deleteAdmById) // 删除管理员

module.exports = router